//
//  XMGLoginRegisterViewController.m
//  BuDeJie
//
//  Created by 1 on 16/6/1.
//  Copyright © 2016年 小码哥. All rights reserved.
//

#import "FLNLoginRegisterViewController.h"
#import "FLNLoginRegisterView.h"
#import "FLNFastLoginView.h"
@interface FLNLoginRegisterViewController()
@property (weak, nonatomic) IBOutlet UIView *middleView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadCons;
@property (weak, nonatomic) IBOutlet UIView *bottomView;

@end

@implementation FLNLoginRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 添加登录view: 一个控件从xib加载,默认跟xib的尺寸一样
    FLNLoginRegisterView *loginView = [FLNLoginRegisterView loginView];
    
    [self.middleView addSubview:loginView];
    
    // 添加注册view
    FLNLoginRegisterView *registerView = [FLNLoginRegisterView registerView];

    [self.middleView addSubview:registerView];
    
    // 添加快速登录view
    FLNFastLoginView *fastLoginView = [FLNFastLoginView fastLoginView];
    [self.bottomView addSubview:fastLoginView];
}

// viewDidLoad里面的子控件执行约束
- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    FLNLoginRegisterView *loginView = self.middleView.subviews[0];
    loginView.frame = CGRectMake(0, 0, self.middleView.width * 0.5, self.middleView.height);
    
    FLNLoginRegisterView *registerView = self.middleView.subviews[1];
     registerView.frame = CGRectMake( self.middleView.width * 0.5, 0, self.middleView.width * 0.5,self.middleView.height);
    
    FLNFastLoginView *fastLoginView = self.bottomView.subviews[0];
    fastLoginView.frame = self.bottomView.bounds;
}

// 点击关闭按钮
- (IBAction)dismiss:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

// 点击注册账号
- (IBAction)clickRegister:(UIButton *)sender {
    sender.selected = !sender.selected;
    
    // 移动中间view
    self.leadCons.constant = self.leadCons.constant == 0 ? -FLNScreenW : 0;
    
    [UIView animateWithDuration:0.25 animations:^{
        // 约束动画
        [self.view layoutIfNeeded];
    }];
}

@end
